home *** CD-ROM | disk | FTP | other *** search
- /* graphics libraries:
- graphics state routines
- by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
- Copyright 1987 - 1991 Apple Computer, Inc. All rights reserved. */
-
- #include <Memory.h>
- #include "graphics libraries.h"
- #include "graphics state library.h"
-
- graphicsState lastGraphicsState = nil;
-
- graphicsState NewGraphicsState(void)
- {
- graphicsState state = (graphicsState) NewPtr(sizeof(graphicsStateRecord));
- short i;
-
- IfErrorReturnNil(state == nil, out_of_memory);
- for (i = gxEmptyType; i <= gxPictureType; i++)
- state->defaultShapes[i - 1] = GXGetDefaultShape(i);
- return lastGraphicsState = state;
- }
-
- void DisposeGraphicsState(graphicsState state)
- {
- NilParamReturn(state);
- if (lastGraphicsState == state)
- lastGraphicsState = nil;
- DisposePtr((Ptr) state);
- }
-
- void GetGraphicsState(graphicsState state)
- {
- short i;
-
- NilParamReturn(state);
- for (i = gxEmptyType; i <= gxPictureType; i++) {
- gxShape def = GXGetDefaultShape(i);
- if (state->defaultShapes[i - 1] != def) {
- GXDisposeShape(state->defaultShapes[i - 1]);
- state->defaultShapes[i - 1] = def;
- }
- }
- }
-
- void SetGraphicsState(graphicsState state)
- {
- short i;
-
- NilParamReturn(state);
- for (i = gxEmptyType; i <= gxPictureType; i++)
- GXSetDefaultShape(state->defaultShapes[i - 1]);
- lastGraphicsState = state;
- }
-
- graphicsState SwapGraphicsState(graphicsState state)
- {
- graphicsState lastState = lastGraphicsState;
-
- if (lastGraphicsState)
- SetGraphicsState(lastGraphicsState);
- if (state)
- SetGraphicsState(state);
- lastGraphicsState = state;
- return lastState;
- }
-
- gxStyle SeparateShapeStyle(gxShape source)
- {
- gxStyle old = GXCloneStyle(GXGetShapeStyle(source)), xnew = GXCopyToStyle(nil, old);
- GXSetShapeStyle(source, xnew);
- GXDisposeStyle(xnew);
- return old;
- }
-
- void ReuniteShapeStyle(gxShape target, gxStyle separate)
- {
- GXSetShapeStyle(target, separate);
- GXDisposeStyle(separate);
- return;
- }
-
- gxInk SeparateShapeInk(gxShape source)
- {
- gxInk old = GXCloneInk(GXGetShapeInk(source)), xnew = GXCopyToInk(nil, old);
- GXSetShapeInk(source, xnew);
- GXDisposeInk(xnew);
- return old;
- }
-
- void ReuniteShapeInk(gxShape target, gxInk separate)
- {
- GXSetShapeInk(target, separate);
- GXDisposeInk(separate);
- return;
- }
-